/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  数据同步事件
	/// module : structs_internal
	/// </summary>
	public class DataSyncEventPOD : IPOD 
    {
        public readonly static Func<DataSyncEventPOD> FACTORY = () => new DataSyncEventPOD();
		public static Func<DataSyncEventPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 游戏服id
        /// </summary>
		public string gameSeverId;
		/// <summary>
        /// 逻辑服id
        /// </summary>
		public string logicSeverId;
		/// <summary>
        /// 同步类型
        /// </summary>
		public DataSyncType type;
		/// <summary>
        /// 玩家id
        /// </summary>
		public long pid;
		/// <summary>
        /// 
        /// </summary>
        private List<ItemPOD> m_items;
		/// <summary>
        /// 
        /// </summary>
        private List<CostItemPOD> m_costItems;
		/// <summary>
        /// 
        /// </summary>
        private List<HeroPOD> m_heroes;
		/// <summary>
        /// 
        /// </summary>
		public FormationPOD formation;
		/// <summary>
        /// 
        /// </summary>
		public UpdatePlayerInfoPOD playerUpdates;
		/// <summary>
        /// 任务参数	
        /// </summary>
        private List<QuestPOD> m_quests;
		/// <summary>
        /// 物品消耗奖励原因
        /// </summary>
		public int reason;
		/// <summary>
        /// 消耗奖励原因参数
        /// </summary>
		public int reasonArg;
		/// <summary>
        /// 主要存储cid
        /// </summary>
        private List<int> m_intParams;
		/// <summary>
        /// 主要存储id	
        /// </summary>
        private List<long> m_longParams;
		/// <summary>
        /// 通用字典参数
        /// </summary>
        private Dictionary<int, int> m_dicParams;
		/// <summary>
        /// 宠物数据
        /// </summary>
		public PetPOD pet;
		
		
        public List<ItemPOD> items
        {
            get
            {
                if(m_items == null)
                {
                    m_items = new();
                }
                return m_items;
            }
            private set => m_items = value;
        }
        public List<ItemPOD> unsafe_items
        {
        	get => m_items;
        	set => m_items = value;
        }
        public List<CostItemPOD> costItems
        {
            get
            {
                if(m_costItems == null)
                {
                    m_costItems = new();
                }
                return m_costItems;
            }
            private set => m_costItems = value;
        }
        public List<CostItemPOD> unsafe_costItems
        {
        	get => m_costItems;
        	set => m_costItems = value;
        }
        public List<HeroPOD> heroes
        {
            get
            {
                if(m_heroes == null)
                {
                    m_heroes = new();
                }
                return m_heroes;
            }
            private set => m_heroes = value;
        }
        public List<HeroPOD> unsafe_heroes
        {
        	get => m_heroes;
        	set => m_heroes = value;
        }
        public List<QuestPOD> quests
        {
            get
            {
                if(m_quests == null)
                {
                    m_quests = new();
                }
                return m_quests;
            }
            private set => m_quests = value;
        }
        public List<QuestPOD> unsafe_quests
        {
        	get => m_quests;
        	set => m_quests = value;
        }
        public List<int> intParams
        {
            get
            {
                if(m_intParams == null)
                {
                    m_intParams = new();
                }
                return m_intParams;
            }
            private set => m_intParams = value;
        }
        public List<int> unsafe_intParams
        {
        	get => m_intParams;
        	set => m_intParams = value;
        }
        public List<long> longParams
        {
            get
            {
                if(m_longParams == null)
                {
                    m_longParams = new();
                }
                return m_longParams;
            }
            private set => m_longParams = value;
        }
        public List<long> unsafe_longParams
        {
        	get => m_longParams;
        	set => m_longParams = value;
        }
        public Dictionary<int, int> dicParams
        {
            get
            {
                if(m_dicParams == null)
                {
                    m_dicParams = new();
                }
                return m_dicParams;
            }
            private set => m_dicParams = value;
        }
        public Dictionary<int, int> unsafe_dicParams
        {
        	get => m_dicParams;
        	set => m_dicParams = value;
        }
		
		/*-- constructors --*/
		public DataSyncEventPOD() {}
		public DataSyncEventPOD(string gameSeverId, string logicSeverId, DataSyncType type, long pid, List<ItemPOD> items, List<CostItemPOD> costItems, List<HeroPOD> heroes, FormationPOD formation, UpdatePlayerInfoPOD playerUpdates, List<QuestPOD> quests, int reason, int reasonArg, List<int> intParams, List<long> longParams, Dictionary<int, int> dicParams, PetPOD pet) {
			this.gameSeverId = gameSeverId;
			this.logicSeverId = logicSeverId;
			this.type = type;
			this.pid = pid;
			this.m_items = items;
			this.m_costItems = costItems;
			this.m_heroes = heroes;
			this.formation = formation;
			this.playerUpdates = playerUpdates;
			this.m_quests = quests;
			this.reason = reason;
			this.reasonArg = reasonArg;
			this.m_intParams = intParams;
			this.m_longParams = longParams;
			this.m_dicParams = dicParams;
			this.pet = pet;
		}
		  public void Serial(SOutputStream _out) {
                if(gameSeverId != default) {
                    _out.WriteByte(1);
                    _out.Write_string(gameSeverId);
                }
                if(logicSeverId != default) {
                    _out.WriteByte(2);
                    _out.Write_string(logicSeverId);
                }
                if(type != default) {
                    _out.WriteByte(3);
                    _out.Write_byte((sbyte)type);
                }
                if(pid != default) {
                    _out.WriteByte(4);
                    _out.Write_long(pid);
                }
                if(m_items != default) {
                    _out.WriteByte(5);
                    _out.Write_list_pod(m_items);
                }
                if(m_costItems != default) {
                    _out.WriteByte(6);
                    _out.Write_list_pod(m_costItems);
                }
                if(m_heroes != default) {
                    _out.WriteByte(7);
                    _out.Write_list_pod(m_heroes);
                }
                if(formation != default) {
                    _out.WriteByte(8);
                    _out.Write_pod(formation);
                }
                if(playerUpdates != default) {
                    _out.WriteByte(9);
                    _out.Write_pod(playerUpdates);
                }
                if(m_quests != default) {
                    _out.WriteByte(10);
                    _out.Write_list_pod(m_quests);
                }
                if(reason != default) {
                    _out.WriteByte(11);
                    _out.Write_int(reason);
                }
                if(reasonArg != default) {
                    _out.WriteByte(12);
                    _out.Write_int(reasonArg);
                }
                if(m_intParams != default) {
                    _out.WriteByte(13);
                    _out.Write_list_int(m_intParams);
                } 
                if(m_longParams != default) {
                    _out.WriteByte(14);
                    _out.Write_list_long(m_longParams);
                } 
                if(m_dicParams != default) {
                    _out.WriteByte(15);
                    _out.Write_map_int_int(m_dicParams);
                }
                if(pet != default) {
                    _out.WriteByte(17);
                    _out.Write_pod(pet);
                }
        }
            
        public void UnSerial(SInputStream _in) {
            while (_in.HasRemaining())
            {
                int _key = _in.ReadByte();
                switch (_key)
                {
                    case 1:
                        gameSeverId = _in.Read_string();
                        break;
                    case 2:
                        logicSeverId = _in.Read_string();
                        break;
                    case 3:
                        type = (DataSyncType)_in.Read_byte();
                        break;
                    case 4:
                        pid = _in.Read_long();
                        break;
                    case 5:
                        m_items = _in.Read_list_pod<ItemPOD>(ItemPOD.DynamicFactory);
                        break;
                    case 6:
                        m_costItems = _in.Read_list_pod<CostItemPOD>(CostItemPOD.DynamicFactory);
                        break;
                    case 7:
                        m_heroes = _in.Read_list_pod<HeroPOD>(HeroPOD.DynamicFactory);
                        break;
                    case 8:
                        formation = _in.Read_pod<FormationPOD>(FormationPOD.DynamicFactory);
                        break;
                    case 9:
                        playerUpdates = _in.Read_pod<UpdatePlayerInfoPOD>(UpdatePlayerInfoPOD.DynamicFactory);
                        break;
                    case 10:
                        m_quests = _in.Read_list_pod<QuestPOD>(QuestPOD.DynamicFactory);
                        break;
                    case 11:
                        reason = _in.Read_int();
                        break;
                    case 12:
                        reasonArg = _in.Read_int();
                        break;
                    case 13:
                        m_intParams = _in.Read_list_int();
                        break;
                    case 14:
                        m_longParams = _in.Read_list_long();
                        break;
                    case 15:
                        m_dicParams = _in.Read_map_int_int();
                        break;
                    case 17:
                        pet = _in.Read_pod<PetPOD>(PetPOD.DynamicFactory);
                        break;
                    default: _in.SkipBinary();break;
                }
            }
        }
		
		public DataSyncEventPOD Clone() {
            DataSyncEventPOD o = DynamicFactory();
            o.gameSeverId = gameSeverId;
            o.logicSeverId = logicSeverId;
            o.type = type;
            o.pid = pid;
            if (m_items != null) {
                o.m_items = m_items.ConvertAll(o => o?.Clone());
            }
            if (m_costItems != null) {
                o.m_costItems = m_costItems.ConvertAll(o => o?.Clone());
            }
            if (m_heroes != null) {
                o.m_heroes = m_heroes.ConvertAll(o => o?.Clone());
            }
            if (formation != null) {
                o.formation = formation.Clone();
            }
            if (playerUpdates != null) {
                o.playerUpdates = playerUpdates.Clone();
            }
            if (m_quests != null) {
                o.m_quests = m_quests.ConvertAll(o => o?.Clone());
            }
            o.reason = reason;
            o.reasonArg = reasonArg;
            if (m_intParams != null) {
                o.m_intParams = new (m_intParams);
            }
            if (m_longParams != null) {
                o.m_longParams = new (m_longParams);
            }
            if (m_dicParams != null) {
                o.m_dicParams = new (m_dicParams);
            }
            if (pet != null) {
                o.pet = pet.Clone();
            }
            return o;
        }
        
        public void Clear() {
            gameSeverId = default;
            logicSeverId = default;
            type = default;
            pid = default;
            m_items = default;
            m_costItems = default;
            m_heroes = default;
            formation = default;
            playerUpdates = default;
            m_quests = default;
            reason = default;
            reasonArg = default;
            m_intParams = default;
            m_longParams = default;
            m_dicParams = default;
            pet = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "DataSyncEventPOD [";
			str += "gameSeverId=";
			str += gameSeverId;
			str += ", logicSeverId=";
			str += logicSeverId;
			str += ", type=";
			str += type;
			str += ", pid=";
			str += pid;
			str += ", items=";
			str += m_items.ToString<ItemPOD>();
			str += ", costItems=";
			str += m_costItems.ToString<CostItemPOD>();
			str += ", heroes=";
			str += m_heroes.ToString<HeroPOD>();
			str += ", formation=";
			str += formation;
			str += ", playerUpdates=";
			str += playerUpdates;
			str += ", quests=";
			str += m_quests.ToString<QuestPOD>();
			str += ", reason=";
			str += reason;
			str += ", reasonArg=";
			str += reasonArg;
			str += ", intParams=";
			str += m_intParams.ToString<int>();
			str += ", longParams=";
			str += m_longParams.ToString<long>();
			str += ", dicParams=";
			str += m_dicParams.ToString<int, int>();
			str += ", pet=";
			str += pet;
			str += "]";
			return str;
		}
		
	}
}